package com.orhonit.ipb.portal.rest;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.orhonit.ipb.portal.biz.JoEducationInvestigationBiz;
import com.orhonit.ipb.portal.entity.JoEducationInvestigation;
import com.orhonit.ipb.portal.entity.JoThoughtReport;
import com.orhonit.ipb.security.auth.client.annotation.CheckClientToken;
import com.orhonit.ipb.security.auth.client.annotation.CheckUserToken;
import com.orhonit.ipb.security.common.rest.BaseController;
import com.orhonit.ipb.security.common.util.UUIDUtils;

@RestController
@RequestMapping("joEducationInvestigation")
//@CheckClientToken
//@CheckUserToken
public class JoEducationInvestigationController extends BaseController<JoEducationInvestigationBiz,JoEducationInvestigation> {

	@Autowired
	private JoEducationInvestigationBiz JoEducationInvestigationBiz;
	/**
	 * 通过申请id及   type:( 0:积极分子：1发展对象；2：预备党员；3：党员)
	 * @param applyId
	 * @param type
	 * @return list
	 */
	@RequestMapping(value = "/getJoEducationInvestigations", method = RequestMethod.GET)
	public ResponseEntity<?> getJoEducationInvestigations(String id){
		JoEducationInvestigation jjJoEducationInvestigations=JoEducationInvestigationBiz.getJoEducationInvestigationlist(id);
		return ResponseEntity.ok().body(jjJoEducationInvestigations);
	}
	/***
	 * 通过申请id type whatType 查询详细消息
	 * @param applyId
	 * @param type
	 * @param whatType
	 * @return
	 */
	@RequestMapping(value = "/getJoEducationInvestigation", method = RequestMethod.GET)
	public ResponseEntity<?> getJoEducationInvestigation(String applyId ,String whatType){
		Map<String, Object> map=new HashMap<String, Object>(); 
		map.put("applyId", applyId);
		map.put("whatType", whatType);
		List<JoEducationInvestigation> jjJoEducationInvestigation=JoEducationInvestigationBiz.getJoEducationInvestigationBymap(map);
		return ResponseEntity.ok().body(jjJoEducationInvestigation);
	}
	/**
	 * 更新教育考察信息
	 * @param data json
	 * @return
	 */
	@RequestMapping(value = "/updateJoEducationInvestigation", method = RequestMethod.POST)
	public ResponseEntity<?> updateJoEducationInvestigation(String data){
		Gson gson = new Gson();
		JoEducationInvestigation jjJoEducationInvestigation = gson.fromJson(data, new TypeToken<JoEducationInvestigation>() {
		}.getType());
		jjJoEducationInvestigation.setCreateTime(new Date());
		if(StringUtils.isNotBlank(jjJoEducationInvestigation.getId())){
			JoEducationInvestigationBiz.updateById(jjJoEducationInvestigation);
		}
		else{
			jjJoEducationInvestigation.setId(UUIDUtils.generateUuid());
			JoEducationInvestigationBiz.insertSelective(jjJoEducationInvestigation);
		}
		JoEducationInvestigationBiz.updateById(jjJoEducationInvestigation);
		return ResponseEntity.ok().body(jjJoEducationInvestigation);
	}
}